package com.collection.vectors;

import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

public class SortVectorComparator {
	public static void main(String[] args) {

		// Create a Vector and populate it with elements
		Vector vector = new Vector();
		vector.add("element_1");
		vector.add("element_3");
		vector.add("element_5");
		vector.add("element_2");
		vector.add("element_4");

		// Vector implementation maintains the insertion order for its elements
		System.out.println("Elements in Vector prior sorting :");
		for (int i = 0; i < vector.size(); i++)

			System.out.println(vector.get(i));

		/*
		 * 
		 * To get a comparator that imposes reverse order on a Collection's
		 * elements
		 * 
		 * we can use static Comparator reverseOrder() operation of Collections
		 * class
		 */
		Comparator comparator = Collections.reverseOrder();

		// Using Collection.sort(List list, Comparator c) static operation we
		// can sort Vector elements using a Comparator
		Collections.sort(vector, comparator);

		System.out.println("Elements in Vector after sorting :");
		for (int i = 0; i < vector.size(); i++)

			System.out.println(vector.get(i));

	}
}
